package aar.test.tessocr.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import aar.test.tessocr.AppointmentOrderNewActivity;
import aar.test.tessocr.CabinetDetailsActivity;
import aar.test.tessocr.baseApplication.BaseApplication;
import aar.test.tessocr.db.impl.ClientInfoDaoImp;
import aar.test.tessocr.model.AppointmentOrderModel;
import aar.test.tessocr.model.CabinetListMpdel;
import clx.tessocr.ocreng.R;

/**
 * Created by 149-201605 on 2016/8/1.
 */

/*
* 主界面显示 dialog的资源适配器
* */
public class AppointmentOrderAdapter extends BaseAdapter {

    private List<AppointmentOrderModel> mList;

    private Context mContext;



    public AppointmentOrderAdapter(Context mContext, List<AppointmentOrderModel> mList) {
        this.mList = mList;
        this.mContext = mContext;


    }

    public void setData(List<AppointmentOrderModel> mList){

        this.mList = mList;
    }


    @Override
    public int getCount() {
        int count = 0;
        if (null != mList && !mList.isEmpty()) {
            count = mList.size();
        }
        return count;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder showDialogHolder = null;
        if (null == convertView) {
            showDialogHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.appointment_order_list_item, null);
            showDialogHolder.grid_type = (TextView) convertView.findViewById(R.id.grid_type);
            showDialogHolder.title_order_id = (TextView) convertView.findViewById(R.id.title_order_id);
            showDialogHolder.title_phone_number = (TextView) convertView.findViewById(R.id.title_phone_number);
            showDialogHolder.delete_grid = (ImageView) convertView.findViewById(R.id.delete_grid);
            showDialogHolder.iv_phone_status = (ImageView) convertView.findViewById(R.id.iv_phone_status);
            convertView.setTag(showDialogHolder);
        } else {
            showDialogHolder = (ViewHolder) convertView.getTag();
        }


        showDialogHolder.grid_type.setText(mList.get(position).getName());

        if(!TextUtils.isEmpty(mList.get(position).getPhone())){
            showDialogHolder.title_phone_number.setText(mList.get(position).getPhone());
            if (ClientInfoDaoImp.getInstance(mContext).hasOldTelNmu(mList.get(position).getPhone())) {
                /*SpannableString spannableString = new SpannableString(mList.get(position).getPhone() + "（旧）");
                //设置颜色
                spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#EE0D00")), 11, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                //设置字体，BOLD为粗体
                spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 11, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);*/
                showDialogHolder.iv_phone_status.setImageResource(R.mipmap.img_old);
            } else {
                /*SpannableString spannableString = new SpannableString(mList.get(position).getPhone() + "（新）");
                //设置颜色
                spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FE6026")), 11, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                //设置字体，BOLD为粗体
                spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 11, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                showDialogHolder.title_phone_number.setText(spannableString);*/
                showDialogHolder.iv_phone_status.setImageResource(R.mipmap.img_new);
            }
        }

        if(!TextUtils.isEmpty(mList.get(position).getExpress())){
            showDialogHolder.title_order_id.setText(mList.get(position).getExpress());

        }
        showDialogHolder.delete_grid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=mdeleteItemListener){
                    mdeleteItemListener.delete(position);
                }
            }
        });


        return convertView;
    }


    class ViewHolder {
        TextView grid_type;
        TextView title_order_id;
        TextView title_phone_number;
        ImageView delete_grid;
        ImageView iv_phone_status;
    }

    public interface deleteItemListener{
        void delete(int pos);
    }

    public void setDeleteItemListener(deleteItemListener mdeleteItemListener){
        this.mdeleteItemListener=mdeleteItemListener;

    }


    private deleteItemListener mdeleteItemListener;
}


